package com.example.demo.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;


import com.example.demo.adapter.ButtonItem;
import com.example.demo.adapter.GridAdapter;
import com.example.demo.R;
import com.example.demo.api.ApiService;
import com.example.demo.api.ResponseData;
import com.example.demo.api.RetrofitClient;

import java.util.Arrays;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {




    List<ButtonItem> buttonItems = Arrays.asList(
            new ButtonItem("打开百度", 1, "https://www.baidu.com"),
            new ButtonItem("H5集成", 2,"http://qr.efangkong.com/sum/"),
            new ButtonItem("组件测试", 3,"http://example.com/3"),
            new ButtonItem("布局测试", 4,"http://example.com/4"),
            new ButtonItem("通知", 5,"http://example.com/5"),
            new ButtonItem("fragment", 6,"http://example.com/6"),
            new ButtonItem("按钮7", 3,"http://example.com/7"),
            new ButtonItem("按钮8", 3,"http://example.com/8"),
            new ButtonItem("按钮9", 3,"http://example.com/9")
    );

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        RecyclerView recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new GridLayoutManager(this, 3));  // 3列

        GridAdapter adapter = new GridAdapter(this, buttonItems);
        recyclerView.setAdapter(adapter);

        ApiService service = RetrofitClient.createService(ApiService.class);
        Call<ResponseData> info = service.getInfo();
        info.enqueue(new Callback<ResponseData>() {
            @Override
            public void onResponse(Call<ResponseData> call, Response<ResponseData> response) {

                if(response.isSuccessful()){
                    Log.d("info", "onResponse: "+response);

                }


            }

            @Override
            public void onFailure(Call<ResponseData> call, Throwable t) {

            }
        });

    }
}